package com.mmy.dao.sys;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.permissionmenu.TConstMenu;

public interface HeaderRepository extends JpaRepository<TConstMenu, Integer> {

	/*
	 * 查找前台全部
	 */
	@Query(value = "select *  from tConstMenu where  left (iMenuID,1) = '1'  and iType = 1 order by iSort", nativeQuery = true)
	List<TConstMenu> getFrontMenuByID();

	/*
	 * 无权限菜单
	 */
	@Query(value = "select * from  tConstMenu where left(iMenuID,2) = '11'  and iType = 1 order by iSort", nativeQuery = true)
	List<TConstMenu> getMenuByID();

	/*
	 * 根据id查找
	 */
	@Query(value = "select *  from tConstMenu where iUpMenuID = :iMenuID and iType = 0 order by iSort", nativeQuery = true)
	List<TConstMenu> getChildrenByMenuID(@Param("iMenuID") int iMenuID);

	/*
	 * 查找后台全部
	 */
	@Query(value = "select *  from tConstMenu where  left (iMenuID,1) = '3'  and iType = 1 order by iSort", nativeQuery = true)
	List<TConstMenu> getBackMenuByID();

	/*
	 * 查找前台
	 */
	@Query(value = "SELECT\r\n" + " * \r\n" + "FROM\r\n" + " tConstMenu m\r\n"
			+ " LEFT JOIN tConstRoleMenu rm ON rm.iMenuID = m.iMenuID\r\n"
			+ " LEFT JOIN tSysUserRole ur ON ur.iRoleID = rm.iRoleID \r\n" + "WHERE\r\n" + " ur.iUserID = :iUserID\r\n"
			+ "and m.iState in(1,3)", nativeQuery = true)
	List<TConstMenu> findFrontByID(@Param("iUserID") int iUserID);

	/*
	 * 查找后台
	 */
	  @Query(value = "SELECT * FROM tConstMenu m" +
	  " LEFT JOIN tConstRoleMenu rm ON rm.iMenuID = m.iMenuID" +
	  " LEFT JOIN tSysUserRole ur ON ur.iRoleID = rm.iRoleID WHERE " +
	  " ur.iUserID = :iUserID and m.iState = 2 ", nativeQuery = true)
	  List<TConstMenu> findBackByID(@Param("iUserID") int iUserID);
}
